package cars

import (
	"time"
)

type CarStruct struct {
	Id         uint      `json:"id" gorm:"type:int(11) unsigned auto_increment; NOT NULL; primary_key"`
	MemberId   int       `json:"member_id" gorm:"type:int(11); COMMENT:'member表id'"`
	Mobile     string    `json:"mobile" gorm:"type:varchar(255); COMMENT:'手机号'"`
	CarNumber  string    `json:"car_number" gorm:"type:varchar(20); COMMENT:'车牌号'"`
	CarInfo    string    `json:"car_info" gorm:"type:varchar(50); COMMENT:'车辆信息'"`
	CarType    int       `json:"car_type" gorm:"type:tinyint(1); COMMENT:'车型 1: 小型车 2: 中型车 3: 大型车 4: 其 他'"`
	CarNoColor int       `json:"car_no_color" gorm:"type:tinyint(1); COMMENT:'车牌颜色 1-蓝牌 3-黄牌 6-绿牌 7-白牌 8-黑牌'"`
	From       int       `json:"from" gorm:"type:tinyint(1); COMMENT:'来源类型'"`
	BindType   int       `json:"bind_type" gorm:"type:tinyint(1); COMMENT:'绑定类型 1永久 2临时'"`
	StartTime  int       `json:"start_time" gorm:"type:int(11); COMMENT:'绑定开始时间'"`
	EndTime    int       `json:"end_time" gorm:"type:int(11); COMMENT:'绑定结束时间'"`
	CreatedAt  time.Time `json:"created_at" gorm:"type:datetime"`
	UpdatedAt  time.Time `json:"updated_at" gorm:"type:datetime"`
}

var colorPlateMap = map[int]string{
	1: "蓝牌",
	3: "黄牌",
	6: "绿牌",
	7: "白牌",
	8: "黑牌",
}

type CarsReturnStruct struct {
	CarStruct
	IsJoin bool `json:"is_join"`
	Park   struct {
		ParkName     string `json:"park_name"`
		InTime       string `json:"in_time"`
		InTimeFormat string `json:"in_time_format"`
		Money        int    `json:"money"`
		Mobile       string `json:"mobile"`
		StopHour     int    `json:"stop_hour"`
		StopMinute   int    `json:"stop_minute"`
	} `gorm:"embedded"`
}

func (c *CarStruct) TableName() string {
	return "cars"
}

// 获取车牌颜色
func (c *CarStruct) GetPlateColor(index int) string {
	if color, ok := colorPlateMap[index]; ok {
		return color
	}
	// 处理无效下标
	return "未知颜色"
}
